package com.ect.client.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class Client {
	public Client() {
		try {
			Socket socket = new Socket("127.0.0.1", 10001);
			PrintStream out = new PrintStream(socket.getOutputStream());
			BufferedReader in= new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			System.out.println("The client is waiting you input... ");
			while (true) {
				String message = br.readLine();
				if ("exit".equals(message)) {
					System.out.println("Client Exit!!");
					out.close();
					in.close();
					br.close();
					socket.close();
					break;
				}
				out.println(message);// print your message to socket
				out.flush();// send message
				System.out.println(in.readLine());// recieve message from server
			}
		} catch (IOException e) {
			System.out.println("Exception happen:" + e);
		}
	}

	public static void main(String[] args) {
		new Client();
	}
}
